;(function($){
    //	/huasheng/WebContent/static/spa/guestAccount/jquery.modal.spa_discount_amount.js
        $.fn.spa_discount_amount = function(opts){
            var el = this;
            var opt = {
                dataBack : function(){},
                closeBack : function(){},
            }
            var param = $.extend(opt,opts);
            var app = new App(el,param);
        }
        
        var App = function(el,param){
            this.el = el;
            this.param = param;
            this.initHtml();
            this.bindEvent();
        }
        
        App.prototype = {
            bindEvent : function(){
                var el = this.el;
                var param = this.param;
                var t = this;
                
                //输入折扣金额
                el.find("#btnDisrateInput").unbind("click").click(function(){
                    //计算器
                    var status = false;
                    el.find("#modal-dialog").hide();
                    if(!$.isFunction($().wechatAlipayPay)){
                        $.ajaxSetup({ async: false, cache: false });
                        $.getScript("js/openSpa/jquery.plugin.digitalCalculator.js");
                        $.ajaxSetup({ async: true });
                    }
                    el.find("#mykeyboard").digitalCalculator({
                        number:el.find("#disrate").val()?el.find("#disrate").val():1,//数量
                        status:status?status:false,
                        title:param.title?param.title:"",
                        //初始化数据返回回调
                        dataBack:function(number){
                            el.find("#modal-dialog").show();
                            el.find("#mykeyboard").hide();
                             el.find("#disrate").val(number);
                        },
                        returnBack :function(){
                            el.find("#modal-dialog").show();
                            el.find("#mykeyboard").hide();
                        }
                    });
                });
                
                //关闭返回
                el.find("#modalBtnCancel,#close-dialog").unbind("click").click(function(){
                    el.modal("hide");
                    el.empty();
                    param.closeBack();
                });
                
                //确定
                el.find("#modalBtnSave").unbind("click").click(function(){
                    
                    t.wait();
                    var postData={};
                    postData.arg = {"xh":param.xh};
                    postData.arg.Field = "disamount";
                    postData.arg.content = el.find("#disrate").val();
                    postData.ct_brxsxm = {discode:"ONE"};
                
                    $.ajax({
                        url: $.HSAPI_AJAXURL+"/qms/mobile/procedure2",
                        type: "post",
                        dataType: "json",
                        data: $.HSAPI_ASKJSONINFO(JSON.stringify(postData),'POSCT_brxsxmEditSave',"{}"),
                        success : function(data){
                            t.goon();
                            if(data.RETURN==1){
                                el.modal("hide");
                                el.empty();
                                param.dataBack();
                            }else{
                                jf_alert(data.MSG);
                            }
                        },
                        error : function(data){
                            t.goon();
                            jf_alert(JSON.stringify(data))
                        }
                    });
                })
            },
            initHtml : function(){
                var el = this.el;
                var param = this.param;
                var t = this;
                
                this.el.addClass("modal").attr("tabindex","-2").attr("data-backdrop","static");
                var html = 	'<div class="mykb-box" id="mykeyboard"></div>'+
                            '<div id="modal-dialog" class="modal-dialog" style="width:600px;">'+
                                '<div id="pageOverlay" class="hide"></div>'+
                                '<div id="loading" class="loading hide">'+
                                    '<i class="ace-icon fa fa-spinner fa-spin orange bigger-250"></i>'+
                                '</div>'+
                                '<div class="modal-content">'+
                                    '<div class="modal-header no-padding">'+
                                        '<div class="table-header">'+
                                            '<button id="close-dialog" type="button" class="close" data-dismiss="modal" aria-hidden="true" value="HTML">'+
                                                '<span class="white">&times;</span>'+
                                            '</button>'+
                                            '<span id="title-dialog">'+$.i18n.propJsp(param.title)+'</span>'+
                                        '</div>'+
                                    '</div>'+
                                    '<div class="modal-body">'+
                                    
                                        '<form id="modal-coupon" class="form-horizontal" role="form">'+
                                            '<div class="space-6"></div>'+
                                            '<div class="form-group" id="coupon_rate">'+
                                                '<label class="col-sm-3 control-label">'+$.i18n.propJsp("折扣金额")+'</label>'+
                                                '<div class="col-sm-9">'+
                                                    '<div class="input-group" style="width:280px;">'+
                                                        '<input type="text" class="form-control search-query input_all" placeholder="" name="disrate" id="disrate">'+
                                                        '<span class="input-group-btn">'+
                                                            '<button type="button" class="btn btn-primary btn-sm" id="btnDisrateInput">'+
                                                                '<span class="ace-icon fa fa-keyboard-o icon-on-right bigger-110"></span>'+
                                                            '</button>'+
                                                        '</span>'+
                                                    '</div>'+
                                                '</div>'+
                                            '</div>'+
                                        '</form>'+
                                        
                                    '</div>'+
                                    '<div class="modal-footer">'+
                                        '<div class="clearfix">'+
                                            '<div class="pull-right">'+
                                                '<div class="btn-group">'+
                                                    '<button id="modalBtnSave" type="button" class="btn btn-sm btn-info">'+
                                                        '<i class="ace-icon fa fa-check"></i>'+
                                                        $.i18n.propJsp("确定")+
                                                    '</button>'+
                                                '</div>'+
                                                '<div class="btn-group">'+
                                                    '<button id="modalBtnCancel" type="button" class="btn btn-sm btn-default">'+
                                                        '<i class="ace-icon fa fa-undo"></i>'+
                                                        $.i18n.propJsp("返回")+
                                                    '</button>'+
                                                '</div>'+
                                            '</div>'+
                                        '</div>'+
                                    '</div>'+
                                '</div>'+
                            '</div>';
                el.html(html);			
            },
            wait : function(){
                var el = this.el;
                el.find("#loading").removeClass("hide");
                el.find("#pageOverlay").removeClass("hide");
            },
            goon : function(){
                var el = this.el;
                el.find("#loading").addClass("hide");
                el.find("#pageOverlay").addClass("hide");
            },
        }
        
        function checkTwoPoint(value){  		
            value=value.toString()+".00";
            value = value.replace(/\.{2,}/g,"."); //只保留第一个, 清除多余的
            value = value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
            value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
            return value;
        }
        
    })(jQuery);